unit uBaseFrame;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, ExtCtrls, StdCtrls, Buttons, uHashClasses;

type
  TNavigatorEvent = procedure (evt: Integer; dbIdx: Integer) of object;
  TDataChangedEvent = procedure (evt: Integer; dbIdx: Integer; newData: TStrings) of object;
  TBaseFrameClass = class of TBaseFrame;

  TBaseFrame = class(TFrame)
    Panel1: TPanel;
    btnSave: TBitBtn;
    btnPrev: TBitBtn;
    btnLast: TBitBtn;
    btnFirst: TBitBtn;
    btnNew: TBitBtn;
    btnEdit: TBitBtn;
    btnDel: TBitBtn;
    btnNext: TBitBtn;
    btnCancel: TBitBtn;
    procedure btnFirstClick(Sender: TObject);
    procedure btnPrevClick(Sender: TObject);
    procedure btnNextClick(Sender: TObject);
    procedure btnLastClick(Sender: TObject);
  private
    { Private declarations }
    FButtonStates: array[0..8] of Boolean;
    FNavigatorEvent: TNavigatorEvent;
    FDataChangedEvent: TDataChangedEvent;
  protected
    FDBIdx: Integer;
    procedure EnabledButtons(BoEnable: Boolean);
    procedure EnabledNavButtons(BoEnable: Boolean);
    procedure PushButtonState;
    procedure PopButtonState;
  public
    { Public declarations }

    function CanClose: Boolean; virtual;
    procedure LoadData(idx: Integer); virtual;

    property OnNavigatorEvent: TNavigatorEvent read FNavigatorEvent write FNavigatorEvent;
    property OnDataChangedEvent: TDataChangedEvent read FDataChangedEvent write FDataChangedEvent;
  end;

implementation

{$R *.dfm}

procedure TBaseFrame.EnabledButtons(BoEnable: Boolean);
begin
  btnNew.Enabled    := BoEnable;
  btnEdit.Enabled   := BoEnable;
  btnDel.Enabled    := BoEnable;
  btnSave.Enabled   := BoEnable;
  btnCancel.Enabled := BoEnable;
  EnabledNavButtons(BoEnable);
end;

procedure TBaseFrame.EnabledNavButtons(BoEnable: Boolean);
begin
  btnFirst.Enabled := BoEnable;
  btnPrev.Enabled  := BoEnable;
  btnNext.Enabled  := BoEnable;
  btnLast.Enabled  := BoEnable;
end;

procedure TBaseFrame.PushButtonState;
begin
  FButtonStates[0] := btnNew.Enabled;
  FButtonStates[1] := btnEdit.Enabled;
  FButtonStates[2] := btnDel.Enabled;
  FButtonStates[3] := btnSave.Enabled;
  FButtonStates[4] := btnCancel.Enabled;
  FButtonStates[5] := btnFirst.Enabled;
  FButtonStates[6] := btnPrev.Enabled;
  FButtonStates[7] := btnNext.Enabled;
  FButtonStates[8] := btnLast.Enabled;
end;

procedure TBaseFrame.PopButtonState;
begin
  btnNew.Enabled := FButtonStates[0];
  btnEdit.Enabled := FButtonStates[1];
  btnDel.Enabled := FButtonStates[2];
  btnSave.Enabled := FButtonStates[3];
  btnCancel.Enabled := FButtonStates[4];
  btnFirst.Enabled := FButtonStates[5];
  btnPrev.Enabled := FButtonStates[6];
  btnNext.Enabled := FButtonStates[7];
  btnLast.Enabled := FButtonStates[8];
end;

procedure TBaseFrame.btnFirstClick(Sender: TObject);
begin
  if Assigned(FNavigatorEvent) then
    FNavigatorEvent(1, FDBIdx);
end;

procedure TBaseFrame.btnLastClick(Sender: TObject);
begin
  if Assigned(FNavigatorEvent) then
    FNavigatorEvent(4, FDBIdx);
end;

procedure TBaseFrame.btnNextClick(Sender: TObject);
begin
  if Assigned(FNavigatorEvent) then
    FNavigatorEvent(3, FDBIdx);
end;

procedure TBaseFrame.btnPrevClick(Sender: TObject);
begin
  if Assigned(FNavigatorEvent) then
    FNavigatorEvent(2, FDBIdx);
end;

function TBaseFrame.CanClose: Boolean;
begin
  result := True;
end;

procedure TBaseFrame.LoadData(idx: Integer);
begin

end;

end.
